package com.wwj.expression;

import com.wwj.domain.LoginUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 自定义权限检验方式
 */
@Component("ex")
public class WWJExpressionRoot {

   public boolean hasAuthority(String authority){
        //获取用户的权限
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        LoginUser loginUser = (LoginUser) authentication.getPrincipal();
        List<String> permissions = loginUser.getPermissions();
        //判断用权限是否含有接口的权限
        return permissions.contains(authority);
    }

}
